package com.westcom.vulb.logic;

import org.json.JSONException;
import org.json.JSONObject;

import android.os.Message;

import com.westcom.vulb.bean.notify_node;
import com.westcom.vulb.network.websocket.VulbWebsocket;
import com.westcom.vulb.protocal.http.Response;

public class ws_req 
{
	private static ws_req mInstance = null;
	public static ws_req getInstance()
	{
		if(null == mInstance)
		{
			mInstance = new ws_req();
		}
		return mInstance;
	}
	
	public int Login(String sessionId,String id,Message msg)
	{
		JSONObject req_js = new JSONObject();
		try 
		{
			JSONObject action = new JSONObject();
			action.put("id",id);
			action.put("code","login");
			action.put("type","req");
			
			JSONObject params = new JSONObject();
			params.put("sessionId",sessionId);
			
			req_js.put("action", action);
			req_js.put("params", params);
		} catch (JSONException e1) 
		{
			// TODO Auto-generated catch block
			e1.printStackTrace();
			return VulbWebsocket.JSON_ERROR;
		}
		return VulbWebsocket.getInstance().send(req_js.toString(),id, msg);
	}
	public int WsHeartBeat()
	{
		String id = "normal";
		JSONObject req_js = new JSONObject();
		try 
		{
			JSONObject action = new JSONObject();
			action.put("code","heartBeat");
			action.put("id",id);
			action.put("type","req");
			
			req_js.put("action", action);
			req_js.put("params", null);
		} catch (JSONException e1) 
		{
			// TODO Auto-generated catch block
			e1.printStackTrace();
			return VulbWebsocket.JSON_ERROR;
		}
		return VulbWebsocket.getInstance().send(req_js.toString(),id, null);
	}
	public int registerForSheetChange(int sheetId,notify_node node,int ws_id)
	{
		return VulbWebsocket.getInstance().registerForSheetEvent(sheetId,node,ws_id);
	}
	public int unregisterForSheetChange(int sheetId,notify_node node,int ws_id)
	{
		return VulbWebsocket.getInstance().unregisterForSheetEvent(sheetId,ws_id);
	}
	public long getWsId()
	{
		return VulbWebsocket.getInstance().getWsId();
	}
}
